package com.faithbj.device.model.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;



@Entity
public class Article extends BaseEntity {

	private static final long serialVersionUID = 1475773294701585482L;

	public static final int MAX_RECOMMEND_ARTICLE_LIST_COUNT = 20;// 推荐文章列表最大文章数
	public static final int MAX_HOT_ARTICLE_LIST_COUNT = 20;// 热点文章列表最大文章数
	public static final int MAX_NEW_ARTICLE_LIST_COUNT = 20;// 最新文章列表最大文章数
	public static final int MAX_NEW_NEWS_LIST_COUNT = 13;// 最新新闻列表最大文章数
	public static final int MAX_PAGE_CONTENT_COUNT = 2000;// 内容分页每页最大字数
	public static final int DEFAULT_ARTICLE_LIST_PAGE_SIZE = 20;// 文章列表默认每页显示数

	private String title;// 标题
	private String author;// 作者
	private String content;// 内容
	private String metaKeywords;// 页面关键词
	private String metaDescription;// 页面描述
	
	private Integer pageCount;// 文章页数
	private ArticleCategory articleCategory;// 文章分类
	private Boolean isPublication;// 是否发布
	
	
	@Column(nullable = false)
	public String getTitle() {
		return title;
	}
	@Column(name="is_publication",columnDefinition="BIT",length=1)
	public Boolean getIsPublication() {
		return isPublication;
	}
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="article_category",nullable = false)
	public ArticleCategory getArticleCategory() {
		return articleCategory;
	}
	public String getAuthor() {
		return author;
	}
	@Lob
	@Column(nullable = false)
	public String getContent() {
		return content;
	}
	@Lob
	@Column(name="meta_keywords")
	public String getMetaKeywords() {
		return metaKeywords;
	}

	@Lob
	@Column(name="meta_description",length = 5000)
	public String getMetaDescription() {
		return metaDescription;
	}


	@Column(name="page_count",nullable = false)
	public Integer getPageCount() {
		return pageCount;
	}
	
	
	public void setIsPublication(Boolean isPublication) {
		this.isPublication = isPublication;
	}


	public void setArticleCategory(ArticleCategory articleCategory) {
		this.articleCategory = articleCategory;
	}	

	public void setTitle(String title) {
		this.title = title;
	}
	public void setAuthor(String author) {
		this.author = author;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public void setMetaKeywords(String metaKeywords) {
		this.metaKeywords = metaKeywords;
	}
	public void setMetaDescription(String metaDescription) {
		this.metaDescription = metaDescription;
	}
	public void setPageCount(Integer pageCount) {
		this.pageCount = pageCount;
	}

	@Transient
	  public void onSave()
	  {
	    if (StringUtils.isEmpty(this.title))
	      this.title = null;
	    if (this.isPublication == null)
	      this.isPublication = Boolean.valueOf(false);
	  }

	  @Transient
	  public void onUpdate()
	  {
		  if (StringUtils.isEmpty(this.title))
		      this.title = null;
		    if (this.isPublication == null)
		      this.isPublication = Boolean.valueOf(false);
	  }

}
